package FileInputStream;
import java.io.*;

public class WriteFile {
    public static void main(String[] args)
    {
        byte buffer[] = new byte[128];
        System.out.println("请输入数据，回车后保存到文件test.txt");
        System.out.println("输入’#‘，则退出");
        try
        {
            FileOutputStream f = new FileOutputStream("d:\\test.txt");
            while(true)
            {
                int n = System.in.read(buffer);
                if(buffer[0] == '#')
                    break;
                f.write(buffer,0,n);
                f.write('\n');
            }
            f.close();
        }
        catch(IOException e)
        {
            System.out.println(e.getMessage());
        }
    }
}
